package com.elm_springboot_s.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class RespondMessage<T> {
    private Integer code; // 状态码 200 成功 404 失败 500 服务器错误
    private String message; // 返回信息
    private T data; // 返回数据

    // 静态方法：成功响应
    public static <T> RespondMessage<T> success(T data) {
        return new RespondMessage<>(HttpStatus.OK.value(), "success", data);
    }

    public static RespondMessage success() {
        return new RespondMessage(HttpStatus.OK.value(), "success", null);
    }

    public static <T> RespondMessage<T> error(String message) {
        return new RespondMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null);
    }
}